﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace NagnagyPrint
{
    public partial class FormConfig : Form
    {
        public FormConfig()
        {
            InitializeComponent();
           
            textBox1.Text = MainForm.DownloadPath;
            textBox2.Text = MainForm.OrdersUrl;
            textBox3.Text = MainForm.OrdersManage;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //browse file dialog
          

            DialogResult result = this.folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                // the code here will be executed if the user presses Open in
                // the dialog.

                textBox1.Text = this.folderBrowserDialog1.SelectedPath;
                  
            }
          
            
        }
        private static void UpdateSetting(string key, string value)
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings[key].Value = value;
            configuration.Save();

            ConfigurationManager.RefreshSection("appSettings");
        }
        private static void getSetting(string key, string value)
        {
            Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            configuration.AppSettings.Settings[key].Value = value;
            configuration.Save();

            ConfigurationManager.RefreshSection("appSettings");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                UpdateSetting("DownloadPath",textBox1.Text);            //
                MainForm.DownloadPath = textBox1.Text;
            }
            if (!string.IsNullOrEmpty(textBox2.Text))
            {
                UpdateSetting("OrdersUrl", textBox2.Text);
                MainForm.OrdersUrl = textBox2.Text;
            }
            if (!string.IsNullOrEmpty(textBox3.Text))
            {
                UpdateSetting("OrdersManage", textBox3.Text);
                MainForm.OrdersManage = textBox3.Text;
            }
           
            this.Close();
        }
    }
}
